package com.ryg.fragment;
import java.util.ArrayList;

import com.ryg.fragment.ui.IndicatorFragmentActivity.TabInfo;
import com.ryg.indicatorfragment.R;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.ViewGroup;
import android.view.Window;

public class startActivity  extends FragmentActivity {

	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		ViewPager v=new ViewPager(this);
		setContentView(getMainViewResId());
		getSupportFragmentManager();
	}
	 /**
     * 返回layout id
     * @return layout id
     */
    protected int getMainViewResId() {
        return R.layout.titled_fragment_tab_activity;
    }
	 public class MyAdapter extends FragmentPagerAdapter {
	        ArrayList<TabInfo> tabs = null;
	        Context context = null;

	        public MyAdapter(Context context, FragmentManager fm, ArrayList<TabInfo> tabs) {
	            super(fm);
	            this.tabs = tabs;
	            this.context = context;
	        }

	        @Override
	        public Fragment getItem(int pos) {
	            Fragment fragment = null;
	            if (tabs != null && pos < tabs.size()) {
	                TabInfo tab = tabs.get(pos);
	                if (tab == null)
	                    return null;
	                fragment = tab.createFragment();
	            }
	            return fragment;
	        }

	        @Override
	        public int getItemPosition(Object object) {
	            return POSITION_NONE;
	        }

	        @Override
	        public int getCount() {
	            if (tabs != null && tabs.size() > 0)
	                return tabs.size();
	            return 0;
	        }

	        @Override
	        public Object instantiateItem(ViewGroup container, int position) {
	            TabInfo tab = tabs.get(position);
	            Fragment fragment = (Fragment) super.instantiateItem(container, position);
	            tab.fragment = fragment;
	            return fragment;
	        }
	    }
}
